﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace word.others
{
    public partial class calculate : Form
    {
        String[] methodArray = { "+", "-", "*", "/" };
        public calculate()
        {
            InitializeComponent();
            load();
        }

        public void load()
        {
            CB_method.Text = methodArray[0];
            CB_method.Items.AddRange(methodArray);
        }

        private void Btn_Ok_Click(object sender, EventArgs e)
        {
            try
            {
                switch (CB_method.Text.ToString())
                {
                    case "+":
                        TB_Resualt.Text = (double.Parse(TB_Number1.Text.ToString()) + double.Parse(TB_Number2.Text.ToString())).ToString();
                        break;
                    case "-":
                        TB_Resualt.Text = (double.Parse(TB_Number1.Text.ToString()) - double.Parse(TB_Number2.Text.ToString())).ToString();
                        break;
                    case "*":
                        TB_Resualt.Text = (double.Parse(TB_Number1.Text.ToString()) * double.Parse(TB_Number2.Text.ToString())).ToString();
                        break;
                    case "/":
                        if (TB_Number2.Text.ToString() != "0")
                        {
                            TB_Resualt.Text = (double.Parse(TB_Number1.Text.ToString()) / double.Parse(TB_Number2.Text.ToString())).ToString();
                        }
                        else
                        {
                            MessageBox.Show("除数不能为零", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        break;
                }
            }
            catch
            {

            }
        }
    }
}
